package com.itsq.controller.resources;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itsq.common.base.BaseController;
import com.itsq.common.bean.ErrorEnum;
import com.itsq.common.bean.Response;
import com.itsq.pojo.dto.PageBannerDto;
import com.itsq.pojo.dto.PageCarDto;
import com.itsq.pojo.entity.Banner;
import com.itsq.pojo.entity.Car;
import com.itsq.service.resources.CarService;
import com.itsq.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 史先帅
 * @since 2021-01-29
 */
@RestController
@RequestMapping("/car")
@AllArgsConstructor
@CrossOrigin
@Api(tags = "汽车信息模块")
public class CarController  extends BaseController {

    @Autowired
    private CarService carService;
//
    @PostMapping("selCarPageFront")
    @ApiOperation(value = "汽车信息模块前台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Car>> selCarPageFront(@RequestBody PageCarDto pageCarDto){
        Page<Car> CarPage = carService.selCarPageFront(pageCarDto);
        return Response.success(CarPage);
    }

    @PostMapping("selCarPageAfter")
    @ApiOperation(value = "管理员——汽车信息模块后台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Car>> selCarPageAfter(@RequestBody PageCarDto pageCarDto){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        Page<Car> CarPage = carService.selCarPageAfter(pageCarDto);
        return Response.success(CarPage);
    }

    @PostMapping("insert")
    @ApiOperation(value = "管理员——汽车信息模块添加", notes = "", httpMethod = "POST")
    public Response<Integer> insert(@RequestBody Car car){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(carService.insert(car));
    }

    @PostMapping("update")
    @ApiOperation(value = "管理员——汽车信息模块修改", notes = "", httpMethod = "POST")
    public Response<Integer> update(@RequestBody Car car){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(carService.update(car));
    }

    @PostMapping("selCarById")
    @ApiOperation(value = "汽车信息模块id查询", notes = "", httpMethod = "POST")
    public Response<Car> selCarById(Integer id){
        return Response.success(carService.selCarById(id));
    }

    @PostMapping("selCarList")
    @ApiOperation(value = "汽车信息模块list查询", notes = "", httpMethod = "POST")
    public Response<List<Car>> selCarList(){
        return Response.success(carService.selCarList());
    }

    @PostMapping("selCarListByCompanyId")
    @ApiOperation(value = "汽车信息模块单位list查询", notes = "", httpMethod = "POST")
    public Response<List<Car>> selCarListByCompanyId(Integer companyId){
        return Response.success(carService.selCarListByCompanyId(companyId));
    }

    @PostMapping("delete")
    @ApiOperation(value = "汽车信息模块删除", notes = "", httpMethod = "POST")
    public Response<Integer> delete(Integer id){
        return Response.success(carService.delete(id));
    }
}

